# -*- coding: utf-8 -*-

import os, time, pandas as pd
from cninfo import cninfo as ci
from tqdm import tqdm

# 1. 获取 A 股列表（剔除退市）
stocks = ci.stock_list(exchange=['sz', 'sh'])
tickers = stocks['code'].tolist()

# 2. 下载目录
OUT_DIR = "./cn_annual_2003_2022"
os.makedirs(OUT_DIR, exist_ok=True)

# 3. 遍历 ticker × 年份
for ticker in tqdm(tickers, desc="Tickers"):
    for year in range(2022, 2023):
        try:
            ci.download_report(code=ticker,
                               report_type='annual',
                               year=year,
                               path=OUT_DIR,
                               rename=f"{ticker}_{year}.pdf")
        except Exception as e:
            # 没有对应年报很常见，跳过
            continue
        time.sleep(0.2)  # 礼貌限速

print("✅ 全部下载完成！")


